1
|
|
|
var ExtensibleData = require('./ExtensibleData'), |
2
|
|
|
SourceCitation = require('./SourceCitation'), |
3
|
|
|
ResourceReference = require('./ResourceReference'), |
4
|
|
|
SourceReference = require('./SourceReference'), |
5
|
|
|
TextValue = require('./TextValue'), |
6
|
|
|
Note = require('./Note'), |
7
|
|
|
Attribution = require('./Attribution'), |
8
|
|
|
Coverage = require('./Coverage'), |
9
|
|
|
Identifiers = require('./Identifiers'), |
10
|
|
|
utils = require('./utils'); |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* A description of a source. |
14
|
|
|
* |
15
|
|
|
* @constructor |
16
|
|
|
* @apram {Object} [json] |
17
|
|
|
*/ |
18
|
|
|
var SourceDescription = function(json){ |
19
|
|
|
|
20
|
|
|
// Protect against forgetting the new keyword when calling the constructor |
21
|
|
|
if(!(this instanceof SourceDescription)){ |
22
|
|
|
return new SourceDescription(json); |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
// If the given object is already an instance then just return it. DON'T copy it. |
26
|
|
|
if(SourceDescription.isInstance(json)){ |
27
|
|
|
return json; |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
ExtensibleData.call(this, json); |
31
|
|
|
|
32
|
|
|
if(json){ |
|
|
|
|
33
|
|
|
this.setResourceType(json.resourceType); |
34
|
|
|
this.setCitations(json.citations); |
35
|
|
|
this.setMediaType(json.mediaType); |
36
|
|
|
this.setAbout(json.about); |
37
|
|
|
this.setMediator(json.mediator); |
38
|
|
|
this.setSources(json.sources); |
39
|
|
|
this.setAnalysis(json.analysis); |
40
|
|
|
this.setComponentOf(json.componentOf); |
41
|
|
|
this.setTitles(json.titles); |
42
|
|
|
this.setNotes(json.notes); |
43
|
|
|
this.setAttribution(json.attribution); |
44
|
|
|
this.setRights(json.rights); |
45
|
|
|
this.setCoverage(json.coverage); |
46
|
|
|
this.setDescriptions(json.descriptions); |
47
|
|
|
this.setIdentifiers(json.identifiers); |
48
|
|
|
this.setCreated(json.created); |
49
|
|
|
this.setModified(json.modified); |
50
|
|
|
this.setRepository(json.repository); |
|
|
|
|
51
|
|
|
} |
52
|
|
|
}; |
53
|
|
|
|
54
|
|
|
SourceDescription.prototype = Object.create(ExtensibleData.prototype); |
55
|
|
|
|
56
|
|
|
SourceDescription._gedxClass = SourceDescription.prototype._gedxClass = 'GedcomX.SourceDescription'; |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* Check whether the given object is an instance of this class. |
60
|
|
|
* |
61
|
|
|
* @param {Object} obj |
62
|
|
|
* @returns {Boolean} |
63
|
|
|
*/ |
64
|
|
|
SourceDescription.isInstance = function(obj){ |
65
|
|
|
return utils.isInstance(obj, this._gedxClass); |
66
|
|
|
}; |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* Get the resource type |
70
|
|
|
* |
71
|
|
|
* @returns {String} |
72
|
|
|
*/ |
73
|
|
|
SourceDescription.prototype.getResourceType = function(){ |
74
|
|
|
return this.resourceType; |
75
|
|
|
}; |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* Set the resource type |
79
|
|
|
* |
80
|
|
|
* @param {String} resourceType |
81
|
|
|
* @returns {SourceDescription} |
82
|
|
|
*/ |
83
|
|
|
SourceDescription.prototype.setResourceType = function(resourceType){ |
84
|
|
|
this.resourceType = resourceType; |
85
|
|
|
return this; |
86
|
|
|
}; |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* Get the citations |
90
|
|
|
* |
91
|
|
|
* @returns {SourceCitation[]} |
92
|
|
|
*/ |
93
|
|
|
SourceDescription.prototype.getCitations = function(){ |
94
|
|
|
return this.citations || []; |
95
|
|
|
}; |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* Set the citations |
99
|
|
|
* |
100
|
|
|
* @param {SourceCitation[]|Object[]} citations |
101
|
|
|
* @returns {SourceDescription} |
102
|
|
|
*/ |
103
|
|
|
SourceDescription.prototype.setCitations = function(citations){ |
104
|
|
|
return this._setArray(citations, 'citations', 'addCitation'); |
105
|
|
|
}; |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* Add a citation |
109
|
|
|
* |
110
|
|
|
* @param {SourceCitation|Object} citation |
111
|
|
|
* @returns {SourceDescription} |
112
|
|
|
*/ |
113
|
|
|
SourceDescription.prototype.addCitation = function(citation){ |
114
|
|
|
return this._arrayPush(citation, 'citations', SourceCitation); |
115
|
|
|
}; |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* Get the media type |
119
|
|
|
* |
120
|
|
|
* @return {String} |
121
|
|
|
*/ |
122
|
|
|
SourceDescription.prototype.getMediaType = function(){ |
123
|
|
|
return this.mediaType; |
124
|
|
|
}; |
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* Set the media type |
128
|
|
|
* |
129
|
|
|
* @param {String} mediaType |
130
|
|
|
* @returns {SourceDescription} |
131
|
|
|
*/ |
132
|
|
|
SourceDescription.prototype.setMediaType = function(mediaType){ |
133
|
|
|
this.mediaType = mediaType; |
134
|
|
|
return this; |
135
|
|
|
}; |
136
|
|
|
|
137
|
|
|
/** |
138
|
|
|
* Get the about property |
139
|
|
|
* |
140
|
|
|
* @returns {String} |
141
|
|
|
*/ |
142
|
|
|
SourceDescription.prototype.getAbout = function(){ |
143
|
|
|
return this.about; |
144
|
|
|
}; |
145
|
|
|
|
146
|
|
|
/** |
147
|
|
|
* Set the about property |
148
|
|
|
* |
149
|
|
|
* @param {String} about |
150
|
|
|
* @returns {SourceDescription} |
151
|
|
|
*/ |
152
|
|
|
SourceDescription.prototype.setAbout = function(about){ |
153
|
|
|
this.about = about; |
154
|
|
|
return this; |
155
|
|
|
}; |
156
|
|
|
|
157
|
|
|
/** |
158
|
|
|
* Get the mediator |
159
|
|
|
* |
160
|
|
|
* @returns {ResourceReference} |
161
|
|
|
*/ |
162
|
|
|
SourceDescription.prototype.getMediator = function(){ |
163
|
|
|
return this.mediator; |
164
|
|
|
}; |
165
|
|
|
|
166
|
|
|
/** |
167
|
|
|
* Set the mediator |
168
|
|
|
* |
169
|
|
|
* @param {ResourceReference} mediator |
170
|
|
|
* @returns {SourceDescription} |
171
|
|
|
*/ |
172
|
|
|
SourceDescription.prototype.setMediator = function(mediator){ |
173
|
|
|
if(mediator){ |
174
|
|
|
this.mediator = ResourceReference(mediator); |
175
|
|
|
} |
176
|
|
|
return this; |
177
|
|
|
}; |
178
|
|
|
|
179
|
|
|
/** |
180
|
|
|
* Get sources |
181
|
|
|
* |
182
|
|
|
* @returns {SourceReference[]} |
183
|
|
|
*/ |
184
|
|
|
SourceDescription.prototype.getSources = function(){ |
185
|
|
|
return this.sources || []; |
186
|
|
|
}; |
187
|
|
|
|
188
|
|
|
/** |
189
|
|
|
* Set the sources |
190
|
|
|
* |
191
|
|
|
* @param {SourceReference[]|Object[]} sources |
192
|
|
|
* @returns {SourceDescription} |
193
|
|
|
*/ |
194
|
|
|
SourceDescription.prototype.setSources = function(sources){ |
195
|
|
|
return this._setArray(sources, 'sources', 'addSource'); |
196
|
|
|
}; |
197
|
|
|
|
198
|
|
|
/** |
199
|
|
|
* Add a source |
200
|
|
|
* |
201
|
|
|
* @param {SourceReference|Object} |
|
|
|
|
202
|
|
|
* @returns {SourceDescription} |
203
|
|
|
*/ |
204
|
|
|
SourceDescription.prototype.addSource = function(source){ |
205
|
|
|
return this._arrayPush(source, 'sources', SourceReference); |
206
|
|
|
}; |
207
|
|
|
|
208
|
|
|
/** |
209
|
|
|
* Get the analysis |
210
|
|
|
* |
211
|
|
|
* @return {ResourceReference} |
212
|
|
|
*/ |
213
|
|
|
SourceDescription.prototype.getAnalysis = function(){ |
214
|
|
|
return this.analysis; |
215
|
|
|
}; |
216
|
|
|
|
217
|
|
|
/** |
218
|
|
|
* Set the analysis |
219
|
|
|
* |
220
|
|
|
* @param {ResourceReference|Object} analysis |
221
|
|
|
* @return {SourceDescription} |
222
|
|
|
*/ |
223
|
|
|
SourceDescription.prototype.setAnalysis = function(analysis){ |
224
|
|
|
if(analysis){ |
225
|
|
|
this.analysis = ResourceReference(analysis); |
226
|
|
|
} |
227
|
|
|
return this; |
228
|
|
|
}; |
229
|
|
|
|
230
|
|
|
/** |
231
|
|
|
* Get the componentOf property |
232
|
|
|
* |
233
|
|
|
* @return {SourceReference} |
234
|
|
|
*/ |
235
|
|
|
SourceDescription.prototype.getComponentOf = function(){ |
236
|
|
|
return this.componentOf; |
237
|
|
|
}; |
238
|
|
|
|
239
|
|
|
/** |
240
|
|
|
* Set the componentOf property |
241
|
|
|
* |
242
|
|
|
* @param {SourceReference} componentOf |
243
|
|
|
*/ |
244
|
|
|
SourceDescription.prototype.setComponentOf = function(componentOf){ |
245
|
|
|
if(componentOf){ |
246
|
|
|
this.componentOf = SourceReference(componentOf); |
247
|
|
|
} |
248
|
|
|
return this; |
249
|
|
|
}; |
250
|
|
|
|
251
|
|
|
/** |
252
|
|
|
* Get titles |
253
|
|
|
* |
254
|
|
|
* @returns {TextValue[]} |
255
|
|
|
*/ |
256
|
|
|
SourceDescription.prototype.getTitles = function(){ |
257
|
|
|
return this.titles || []; |
258
|
|
|
}; |
259
|
|
|
|
260
|
|
|
/** |
261
|
|
|
* Set the titles |
262
|
|
|
* |
263
|
|
|
* @param {TextValue[]|Object[]} titles |
264
|
|
|
* @returns {SourceDescription} |
265
|
|
|
*/ |
266
|
|
|
SourceDescription.prototype.setTitles = function(titles){ |
267
|
|
|
return this._setArray(titles, 'titles', 'addTitle'); |
268
|
|
|
}; |
269
|
|
|
|
270
|
|
|
/** |
271
|
|
|
* Add a title |
272
|
|
|
* |
273
|
|
|
* @param {TextValue|Object} |
|
|
|
|
274
|
|
|
* @returns {SourceDescription} |
275
|
|
|
*/ |
276
|
|
|
SourceDescription.prototype.addTitle = function(title){ |
277
|
|
|
return this._arrayPush(title, 'titles', TextValue); |
278
|
|
|
}; |
279
|
|
|
|
280
|
|
|
/** |
281
|
|
|
* Get notes |
282
|
|
|
* |
283
|
|
|
* @returns {Note[]} |
284
|
|
|
*/ |
285
|
|
|
SourceDescription.prototype.getNotes = function(){ |
286
|
|
|
return this.notes || []; |
287
|
|
|
}; |
288
|
|
|
|
289
|
|
|
/** |
290
|
|
|
* Set the notes |
291
|
|
|
* |
292
|
|
|
* @param {Note[]|Object[]} notes |
293
|
|
|
* @returns {SourceDescription} |
294
|
|
|
*/ |
295
|
|
|
SourceDescription.prototype.setNotes = function(notes){ |
296
|
|
|
return this._setArray(notes, 'notes', 'addNote'); |
297
|
|
|
}; |
298
|
|
|
|
299
|
|
|
/** |
300
|
|
|
* Add a source |
301
|
|
|
* |
302
|
|
|
* @param {Note|Object} note |
303
|
|
|
* @returns {SourceDescription} |
304
|
|
|
*/ |
305
|
|
|
SourceDescription.prototype.addNote = function(note){ |
306
|
|
|
return this._arrayPush(note, 'notes', Note); |
307
|
|
|
}; |
308
|
|
|
|
309
|
|
|
/** |
310
|
|
|
* Get the attribution |
311
|
|
|
* |
312
|
|
|
* @returns {Attribution} |
313
|
|
|
*/ |
314
|
|
|
SourceDescription.prototype.getAttribution = function(){ |
315
|
|
|
return this.attribution; |
316
|
|
|
}; |
317
|
|
|
|
318
|
|
|
/** |
319
|
|
|
* Set the attribution |
320
|
|
|
* |
321
|
|
|
* @param {Attribution|Object} attribution |
322
|
|
|
* @returns {SourceDescription} |
323
|
|
|
*/ |
324
|
|
|
SourceDescription.prototype.setAttribution = function(attribution){ |
325
|
|
|
if(attribution){ |
326
|
|
|
this.attribution = Attribution(attribution); |
327
|
|
|
} |
328
|
|
|
return this; |
329
|
|
|
}; |
330
|
|
|
|
331
|
|
|
/** |
332
|
|
|
* Get the rights |
333
|
|
|
* |
334
|
|
|
* @returns {ResourceReference[]} |
335
|
|
|
*/ |
336
|
|
|
SourceDescription.prototype.getRights = function(){ |
337
|
|
|
return this.rights || []; |
338
|
|
|
}; |
339
|
|
|
|
340
|
|
|
/** |
341
|
|
|
* Set the rights |
342
|
|
|
* |
343
|
|
|
* @param {ResourceReference[]|Object[]} rights |
344
|
|
|
* @returns {SourceDescription} |
345
|
|
|
*/ |
346
|
|
|
SourceDescription.prototype.setRights = function(rights){ |
347
|
|
|
return this._setArray(rights, 'rights', 'addRight'); |
348
|
|
|
}; |
349
|
|
|
|
350
|
|
|
/** |
351
|
|
|
* Add a source |
352
|
|
|
* |
353
|
|
|
* @param {ResourceReference|Object} right |
354
|
|
|
* @returns {SourceDescription} |
355
|
|
|
*/ |
356
|
|
|
SourceDescription.prototype.addRight = function(right){ |
357
|
|
|
return this._arrayPush(right, 'rights', ResourceReference); |
358
|
|
|
}; |
359
|
|
|
|
360
|
|
|
/** |
361
|
|
|
* Get the coverage |
362
|
|
|
* |
363
|
|
|
* @returns {Coverage} |
364
|
|
|
*/ |
365
|
|
|
SourceDescription.prototype.getCoverage = function(){ |
366
|
|
|
return this.coverage; |
367
|
|
|
}; |
368
|
|
|
|
369
|
|
|
/** |
370
|
|
|
* Set the coverage |
371
|
|
|
* |
372
|
|
|
* @param {Coverage|Object} coverage |
373
|
|
|
* @returns {SourceDescription} |
374
|
|
|
*/ |
375
|
|
|
SourceDescription.prototype.setCoverage = function(coverage){ |
376
|
|
|
if(coverage){ |
377
|
|
|
this.coverage = Coverage(coverage); |
378
|
|
|
} |
379
|
|
|
return this; |
380
|
|
|
}; |
381
|
|
|
|
382
|
|
|
/** |
383
|
|
|
* Get the descriptions |
384
|
|
|
* |
385
|
|
|
* @returns {TextValue[]} |
386
|
|
|
*/ |
387
|
|
|
SourceDescription.prototype.getDescriptions = function(){ |
388
|
|
|
return this.descriptions || []; |
389
|
|
|
}; |
390
|
|
|
|
391
|
|
|
/** |
392
|
|
|
* Set the descriptions |
393
|
|
|
* |
394
|
|
|
* @param {TextValue[]|Object[]} descriptions |
395
|
|
|
* @returns {SourceDescription} |
396
|
|
|
*/ |
397
|
|
|
SourceDescription.prototype.setDescriptions = function(descriptions){ |
398
|
|
|
return this._setArray(descriptions, 'descriptions', 'addDescription'); |
399
|
|
|
}; |
400
|
|
|
|
401
|
|
|
/** |
402
|
|
|
* Add a description |
403
|
|
|
* |
404
|
|
|
* @param {TextValue|Object} |
|
|
|
|
405
|
|
|
* @returns {SourceDescription} |
406
|
|
|
*/ |
407
|
|
|
SourceDescription.prototype.addDescription = function(description){ |
408
|
|
|
return this._arrayPush(description, 'descriptions', TextValue); |
409
|
|
|
}; |
410
|
|
|
|
411
|
|
|
/** |
412
|
|
|
* Get the identifiers |
413
|
|
|
* |
414
|
|
|
* @returns {Identifiers} |
415
|
|
|
*/ |
416
|
|
|
SourceDescription.prototype.getIdentifiers = function(){ |
417
|
|
|
return this.identifiers; |
418
|
|
|
}; |
419
|
|
|
|
420
|
|
|
/** |
421
|
|
|
* Set the identifiers |
422
|
|
|
* |
423
|
|
|
* @param {Identifiers} identifiers |
424
|
|
|
* @returns {SourceDescription} |
425
|
|
|
*/ |
426
|
|
|
SourceDescription.prototype.setIdentifiers = function(identifiers){ |
427
|
|
|
if(identifiers){ |
428
|
|
|
this.identifiers = Identifiers(identifiers); |
429
|
|
|
} |
430
|
|
|
return this; |
431
|
|
|
}; |
432
|
|
|
|
433
|
|
|
/** |
434
|
|
|
* Get the created timestamp |
435
|
|
|
* |
436
|
|
|
* @returns {Integer} |
437
|
|
|
*/ |
438
|
|
|
SourceDescription.prototype.getCreated = function(){ |
439
|
|
|
return this.created; |
440
|
|
|
}; |
441
|
|
|
|
442
|
|
|
/** |
443
|
|
|
* Set the created timestamp |
444
|
|
|
* |
445
|
|
|
* @param {Integer} created |
446
|
|
|
* @returns {SourceDescription} |
447
|
|
|
*/ |
448
|
|
|
SourceDescription.prototype.setCreated = function(created){ |
449
|
|
|
this.created = created; |
450
|
|
|
return this; |
451
|
|
|
}; |
452
|
|
|
|
453
|
|
|
/** |
454
|
|
|
* Get the modified timestamp |
455
|
|
|
* |
456
|
|
|
* @returns {Integer} |
457
|
|
|
*/ |
458
|
|
|
SourceDescription.prototype.getModified = function(){ |
459
|
|
|
return this.modified; |
460
|
|
|
}; |
461
|
|
|
|
462
|
|
|
/** |
463
|
|
|
* Set the modified timestamp |
464
|
|
|
* |
465
|
|
|
* @param {Integer} modified |
466
|
|
|
* @returns {SourceDescription} |
467
|
|
|
*/ |
468
|
|
|
SourceDescription.prototype.setModified = function(modified){ |
469
|
|
|
this.modified = modified; |
470
|
|
|
return this; |
471
|
|
|
}; |
472
|
|
|
|
473
|
|
|
/** |
474
|
|
|
* Get the repository |
475
|
|
|
* |
476
|
|
|
* @returns {ResourceReference} |
477
|
|
|
*/ |
478
|
|
|
SourceDescription.prototype.getRepository = function(){ |
479
|
|
|
return this.repository; |
480
|
|
|
}; |
481
|
|
|
|
482
|
|
|
/** |
483
|
|
|
* Set the repository |
484
|
|
|
* |
485
|
|
|
* @param {ResourceReference} repository |
486
|
|
|
* @returns {SourceDescription} |
487
|
|
|
*/ |
488
|
|
|
SourceDescription.prototype.setRepository = function(repository){ |
489
|
|
|
if(repository){ |
490
|
|
|
this.repository = ResourceReference(repository); |
491
|
|
|
} |
492
|
|
|
return this; |
493
|
|
|
}; |
494
|
|
|
|
495
|
|
|
/** |
496
|
|
|
* Export the object as JSON |
497
|
|
|
* |
498
|
|
|
* @return {Object} JSON object |
499
|
|
|
*/ |
500
|
|
|
SourceDescription.prototype.toJSON = function(){ |
501
|
|
|
return this._toJSON(ExtensibleData, [ |
502
|
|
|
'resourceType', |
503
|
|
|
'citations', |
504
|
|
|
'mediaType', |
505
|
|
|
'about', |
506
|
|
|
'mediator', |
507
|
|
|
'sources', |
508
|
|
|
'analysis', |
509
|
|
|
'componentOf', |
510
|
|
|
'titles', |
511
|
|
|
'notes', |
512
|
|
|
'attribution', |
513
|
|
|
'rights', |
514
|
|
|
'coverage', |
515
|
|
|
'descriptions', |
516
|
|
|
'identifiers', |
517
|
|
|
'created', |
518
|
|
|
'modified', |
519
|
|
|
'repository' |
520
|
|
|
]); |
521
|
|
|
}; |
522
|
|
|
|
523
|
|
|
module.exports = SourceDescription; |
This check looks for functions where a
return
statement is found in some execution paths, but not in all.Consider this little piece of code
The function
isBig
will only return a specific value when its parameter is bigger than 5000. In any other case, it will implicitly returnundefined
.This behaviour may not be what you had intended. In any case, you can add a
return undefined
to the other execution path to make the return value explicit.